package com.javatest2;

import java.util.Arrays;

/**
 * @author LL
 * 冒泡排序
 * @create 2021-01-20 18:06
 */
public class Subject9 {

    public static void test(final int[] a) {
        for (int i = 0; i < a.length - 1; i++) {
            boolean flag = true;
            for (int j = 0; j < a.length - 1 - i; j++) {
                if (a[j] > a[j + 1]) {
                    final int temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                    flag = false;
                }
            }
            if (flag) {
                break;
            }
        }
        System.out.println(Arrays.toString(a));
    }

    public static void main(final String[] args) {
        final int[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9};
        test(a);
    }
}
